package com.mconnect.msurvey.controller;

import java.util.HashMap;
import java.util.List;

import org.hibernate.Session;

import com.mconnect.msurvey.model.ResponderConfirm;
import com.mconnect.msurvey.util.HibernateUtil;

public class ConfirmManager extends HibernateUtil{
	
	public ResponderConfirm getConfirmByIdResponder(int idResponder){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.getTransaction().begin();
		
        ResponderConfirm confirm = (ResponderConfirm) session.createQuery("from ResponderConfirm where id_responder=" + idResponder).uniqueResult();
        
        session.getTransaction().commit();
		return confirm;
	}
	
	@SuppressWarnings("unchecked")
	public HashMap<String, String> getPeselInfoByIdResponder(int id_responder){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.getTransaction().begin();
		HashMap<String, String> map = new HashMap<String, String>();
		List<Object []>list =  (List<Object[]>) session.createSQLQuery("SELECT pesel, peselDate, pesel_id_user, note FROM responder_confirm c inner join responder r on c.id_responder = r.id_responder where c.id_responder=" + id_responder).list();
		for (Object [] object : list) {
			if(object[0] != null)
				map.put("pesel", object[0].toString());
			if(object[1] != null)
				map.put("data", object[1].toString());
			if(object[2] != null)
				map.put("peselUser", object[2].toString());
			if(object[3] != null)
			map.put("note", object[3].toString());
		}
		session.getTransaction().commit();
		return map;
	}
	

}
